/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Presentation;

import BussinesLogic.BL_Colaborador;
import BussinesLogic.Request;
import java.util.Date;
import javax.swing.*;

public class GUIRegColaborador extends javax.swing.JFrame {

    private String idEvento;
    public boolean transact;
    
    public GUIRegColaborador(String idEvento) {
        this.idEvento = idEvento;
        this.setVisible(true);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelGeneral = new javax.swing.JPanel();
        panelPersona = new javax.swing.JPanel();
        labelNombre = new javax.swing.JLabel();
        campoNombre = new javax.swing.JTextField();
        labelLugarNac = new javax.swing.JLabel();
        labelApellido = new javax.swing.JLabel();
        labelId = new javax.swing.JLabel();
        labelPaisNac = new javax.swing.JLabel();
        campoPaisNac = new javax.swing.JTextField();
        campoId = new javax.swing.JTextField();
        campoApellido = new javax.swing.JTextField();
        campoFechaNac = new com.toedter.calendar.JDateChooser();
        labelNacionalidad = new javax.swing.JLabel();
        campoNacionalidad = new javax.swing.JTextField();
        botonNac = new javax.swing.JButton();
        panelColab = new javax.swing.JPanel();
        labelCargo = new javax.swing.JLabel();
        labelUsername = new javax.swing.JLabel();
        labelPassword = new javax.swing.JLabel();
        campoUsername = new javax.swing.JTextField();
        campoCargo = new javax.swing.JComboBox();
        campoPassword = new javax.swing.JPasswordField();
        botonRegistrar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("JOGOS2016 - Registrar Colaborador");

        panelPersona.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        labelNombre.setText("NOMBRE");

        labelLugarNac.setText("FECHA DE NACIMIENTO");

        labelApellido.setText("APELLIDO");

        labelId.setText("N° IDENTIFICACION");

        labelPaisNac.setText("PAIS DE NACIMIENTO");

        labelNacionalidad.setText("NACIONALIDAD");

        campoNacionalidad.setEditable(false);
        campoNacionalidad.setBackground(new java.awt.Color(204, 204, 204));

        botonNac.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        botonNac.setText("Add Nac");
        botonNac.setMargin(new java.awt.Insets(0, 0, 0, 0));
        botonNac.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonNacActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelPersonaLayout = new javax.swing.GroupLayout(panelPersona);
        panelPersona.setLayout(panelPersonaLayout);
        panelPersonaLayout.setHorizontalGroup(
            panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPersonaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(panelPersonaLayout.createSequentialGroup()
                            .addGroup(panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(labelPaisNac)
                                .addComponent(labelId)
                                .addComponent(labelApellido)
                                .addComponent(labelNombre))
                            .addGap(14, 14, 14))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPersonaLayout.createSequentialGroup()
                            .addComponent(labelLugarNac)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                    .addGroup(panelPersonaLayout.createSequentialGroup()
                        .addComponent(labelNacionalidad)
                        .addGap(43, 43, 43)))
                .addGroup(panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(campoNacionalidad)
                        .addComponent(campoFechaNac, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
                        .addComponent(campoPaisNac, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(campoId, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(campoApellido, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(campoNombre, javax.swing.GroupLayout.Alignment.LEADING))
                    .addComponent(botonNac, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelPersonaLayout.setVerticalGroup(
            panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPersonaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNombre)
                    .addComponent(campoNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelApellido)
                    .addComponent(campoApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelId))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelPaisNac)
                    .addComponent(campoPaisNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(campoFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelLugarNac))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelNacionalidad)
                    .addComponent(campoNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonNac, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelColab.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        labelCargo.setText("CARGO");

        labelUsername.setText("USUARIO");

        labelPassword.setText("CONTRASEÑA");

        campoCargo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Director Deportivo", "Director de Logistica" }));

        javax.swing.GroupLayout panelColabLayout = new javax.swing.GroupLayout(panelColab);
        panelColab.setLayout(panelColabLayout);
        panelColabLayout.setHorizontalGroup(
            panelColabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelColabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelColabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelPassword)
                    .addComponent(labelUsername)
                    .addComponent(labelCargo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelColabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(campoUsername, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoPassword)
                    .addComponent(campoCargo, javax.swing.GroupLayout.Alignment.LEADING, 0, 144, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelColabLayout.setVerticalGroup(
            panelColabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelColabLayout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(panelColabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelUsername)
                    .addComponent(campoUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelColabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelPassword)
                    .addComponent(campoPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelColabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelCargo)
                    .addComponent(campoCargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        botonRegistrar.setText("REGISTRAR");
        botonRegistrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonRegistrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelGeneralLayout = new javax.swing.GroupLayout(panelGeneral);
        panelGeneral.setLayout(panelGeneralLayout);
        panelGeneralLayout.setHorizontalGroup(
            panelGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelGeneralLayout.createSequentialGroup()
                .addComponent(panelPersona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelGeneralLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(botonRegistrar)
                .addGap(88, 88, 88))
            .addGroup(panelGeneralLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(panelColab, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelGeneralLayout.setVerticalGroup(
            panelGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelGeneralLayout.createSequentialGroup()
                .addComponent(panelPersona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panelColab, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addComponent(botonRegistrar))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(panelGeneral, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(35, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelGeneral, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonRegistrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonRegistrarActionPerformed
        // TODO add your handling code here:
        if(!checkCamposVacios()){
            BL_Colaborador bl_Colaborador = new BL_Colaborador();
            Request rqst = bl_Colaborador.registrarColaborador(campoId.getText(), campoNombre.getText(), campoApellido.getText(), 
                    campoPaisNac.getText(), campoFechaNac.getDate(), campoNacionalidad.getText(), campoUsername.getText(),
                    campoPassword.getText(), campoCargo.getSelectedItem().toString(), idEvento);
            
            JOptionPane.showMessageDialog(this,rqst.getMessage(),
                    "JOGOS2016 - Mensaje",JOptionPane.INFORMATION_MESSAGE);
            if(rqst.getTransac()){
                this.dispose();
                this.transact=true;
            }
            
        }
        else{
            JOptionPane.showMessageDialog(this,"Por favor diligenciar todos los campos del formulario",
                    "JOGOS2016 - Error",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_botonRegistrarActionPerformed

    private void botonNacActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonNacActionPerformed
        // TODO add your handling code here:
        String s = JOptionPane.showInputDialog("Por favor escriba una nacionalidad para adicionar");
        if(!(s.isEmpty() || s==null))campoNacionalidad.setText(campoNacionalidad.getText()+s+",");
        
        
    }//GEN-LAST:event_botonNacActionPerformed

    private boolean checkCamposVacios(){
        
        String nombre = this.campoNombre.getText();
        String apellido = this.campoApellido.getText();
        String id = this.campoId.getText();
        String pais = this.campoPaisNac.getText();
        String nacionalidad = this.campoNacionalidad.getText();
        String user = this.campoUsername.getText();
        String pass = this.campoPassword.getText();
        Date fecha = this.campoFechaNac.getDate();
        
        if(nombre.isEmpty() || apellido.isEmpty() || id.isEmpty() || pais.isEmpty() || nacionalidad.isEmpty() ||
                user.isEmpty() || pass.isEmpty() || fecha==null){
            return true;
        }
        else return false;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonNac;
    private javax.swing.JButton botonRegistrar;
    private javax.swing.JTextField campoApellido;
    private javax.swing.JComboBox campoCargo;
    private com.toedter.calendar.JDateChooser campoFechaNac;
    private javax.swing.JTextField campoId;
    private javax.swing.JTextField campoNacionalidad;
    private javax.swing.JTextField campoNombre;
    private javax.swing.JTextField campoPaisNac;
    private javax.swing.JPasswordField campoPassword;
    private javax.swing.JTextField campoUsername;
    private javax.swing.JLabel labelApellido;
    private javax.swing.JLabel labelCargo;
    private javax.swing.JLabel labelId;
    private javax.swing.JLabel labelLugarNac;
    private javax.swing.JLabel labelNacionalidad;
    private javax.swing.JLabel labelNombre;
    private javax.swing.JLabel labelPaisNac;
    private javax.swing.JLabel labelPassword;
    private javax.swing.JLabel labelUsername;
    private javax.swing.JPanel panelColab;
    private javax.swing.JPanel panelGeneral;
    private javax.swing.JPanel panelPersona;
    // End of variables declaration//GEN-END:variables
}
